<template>
	<view class="padding32">
		<u-navbar titleStyle="font-size:40rpx;color:#333" :placeholder='true' :title="type==1?'收货地址':'编辑地址'"
			:autoBack="true"></u-navbar>
		
		<view class="lis flexJBC">
			<view class="fontS32 name fw7">
				下单人
			</view>
			<u-input placeholder="请输入下单人姓名" inputAlign='right'  border='none' placeholderStyle='color:#999;fontsize:32rpx;text-align:right'
				v-model="form.real_name">
			</u-input> 
		</view>
		<view class="lis flexJBC">
			<view class="fontS32 name fw7">
				下单人手机号
			</view>
			<u-input inputAlign='right' :customStyle="{marginLeft:'100rpx'}" placeholder="请输入下单人手机号" border='none' placeholderStyle='color:#999;fontsize:32rpx'
				v-model="form.phone" type="number">
				<view class="fontS32 flex relative" slot="prefix" style="align-items:baseline;">
					<view class="selectbox" v-if="showArea">
						<view class="triangle">  
						</view>
						<view class="box">
							<scroll-view scroll-y="true" style="min-height: 10vh;max-height: 30vh;">
								<view v-for="(item,index) in listArea" :key="index" class="lis   fontS24 elipes1"
									@click="form.phone_prefix=item.prefix;showArea=false">
									+{{item.prefix}}
								</view>
							</scroll-view>
						</view>
					</view>
				</view>
			</u-input>
		</view>
		<view class="lis flexJBC">
			<view class="fontS32 name fw7">
				提货人
			</view>
			<u-input placeholder="请输入提货人姓名" inputAlign='right'  border='none' placeholderStyle='color:#999;fontsize:32rpx;text-align:right'
				v-model="form.take_name">
			</u-input>
		</view>
		<view class="lis flexJBC">
			<view class="fontS32 name fw7">
				提货人手机号
			</view>
			<u-input inputAlign='right' :customStyle="{marginLeft:'100rpx'}" placeholder="请输入提货人手机号"  border='none' placeholderStyle='color:#999;fontsize:32rpx'
				v-model="form.take_phone" type="number" >
				<view class="fontS32 flex relative" slot="prefix" style="align-items:baseline;">
					<view class="selectbox" v-if="showArea">
						<view class="triangle">
						</view>
						<view class="box">
							<scroll-view scroll-y="true" style="min-height: 10vh;max-height: 30vh;">
								<view v-for="(item,index) in listArea" :key="index" class="lis   fontS24 elipes1"
									@click="form.phone_prefix=item.prefix;showArea=false">
									+{{item.prefix}}
								</view>
							</scroll-view>
						</view>
					</view>
				</view>
			</u-input>
		</view>
		<view class="lis flexJBC">
			<view class="fontS32 name fw7">
				提货公司
			</view>
			<u-input inputAlign='right'  :customStyle="{marginLeft:'100rpx'}" placeholder="请输入提货公司名称" border='none' placeholderStyle='color:#999;fontsize:32rpx'
				v-model="form.take_company_name" >
			</u-input> 
		</view>
		<view class="flexJBC mt32">
			<view class="fontS32 fw7 ">
				设为默认地址:
			</view>
			<u-switch v-model="is_default" size="20" activeColor="#DD2131"></u-switch>
		</view>
		<view class="fixed bottomBtn cof ">
			<u-button :loading='loading' class="btn bgcred cof fontS28 " @click="AddOrEdit">
				保存
			</u-button>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				is_default: false, //是否为默认地址
				form: {
					real_name: '', //姓名
					phone: '', //手机号
					take_company_name:'',
					take_phone:'',
					take_name:'',
				},
				type: 1, //1是添加 2是编辑
				showArea: false,
			}
		},
		onLoad(option) {
			if (option.id) {
				this.id = option.id
				this.type = 2
				this.$my.post('/index/user/get_address_info', {
					id: this.id
				}).then(res => {
					if (res.code == 200) {
						let res1 = res.data
						this.is_default = res1.is_default == 1
						this.form = {
							real_name: res1.real_name,
							phone: res1.phone,
							take_company_name:res1.take_company_name,
							take_phone:res1.take_phone,
							take_name:res1.take_name,
							id: this.id
						}
					}
				})
			}
		},
		methods: {
			// 修改或者新增地址
			AddOrEdit() {
				if (!uni.$u.test.mobile(this.form.phone)  ||  !uni.$u.test.mobile(this.form.take_phone)) {
					this.$my.toast('手机格式有误')
					return
				};
				this.loading = true;
				// 增 和 修改 ，有id表示值表示修改
				let aa = {
					is_default: this.is_default ? 1 : 0 
				}
				this.$my.post('/index/user/save_address', Object.assign(aa, this.form)).then(res => {
					this.loading = false;
					this.$my.toast(res.message)
					if (res.code == 200) {
						setTimeout(() => {
							this.$my.go()
						}, 500)
					}
				})
			},
		}
	}
</script>
<style>
	page {
		background-color: #fff;

	}
</style>
<style lang="scss" scoped>
	// /deep/.u-input__content{
	// 	background: #fff !important;
	// }
	/deep/ .uni-textarea-textarea{
		color: #333;
		font-size: 32rpx;
	}
	/deep/.uni-input-input{
		font-size: 32rpx;
		
	}
	.listtitle {
		// padding-left: 12rpx;
		margin-left: 30rpx;
		line-height: 60rpx;
		position: relative;

		&::after {
			content: '';
			width: 100%;
			height: 2rpx;
			background-color: var(--color);
			position: absolute;
			bottom: 0;
			left: 0;
		}
	}

	.listline {
		height: 80rpx;
		line-height: 80rpx;
		border-bottom: 1rpx solid #f9f9f9;
	}

	.popupBox {
		height: 60vh;

	}

	.selectbox {
		position: absolute;
		width: 150rpx;
		z-index: 999;
		top: 30rpx;

		.lis {
			display: flex;
			justify-content: center;
			height: 88rpx;
			line-height: 88rpx;
			border-bottom: 1px solid rgba(129, 129, 129, 0.1216);
		}

		.triangle {
			width: 36rpx;
			height: 36rpx;
			background-color: #fff;
			left: 50%;
			transform: translateX(-50%) rotate(50deg);
			text-align: center;
			position: absolute;
			top: 20rpx;
			z-index: 99;
		}

		.box {
			padding: 0 24rpx;
			box-sizing: border-box;
			position: absolute;
			width: 100%;
			min-height: 10vh;
			max-height: 40vh;
			background-color: #fff;
			box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1000);
			top: 35rpx;
			left: 0;
		}
	}

	.bottomBtn {
		.btn {
			height: 80rpx;
			line-height: 80rpx;
			border-radius: 40rpx;
		}

		background-color: #fff;
		padding: 16rpx 32rpx;
		box-sizing: border-box;
		bottom: 0;
		width: 100%;
		left: 0;

	}

	/deep/.u-textarea {
		padding: 0;
	}

	.lis {
		border-bottom: 1rpx solid rgba(51, 51, 51, 0.06);
		padding-bottom: 24rpx;
		padding-top: 16rpx;
	}

	.name {
		// margin-right: 72rpx;
		width: 200rpx;

	}
</style>
